# 编写异步任务
from ronglian_sms_sdk import SmsSDK
from celery_tasks.sms import constants
from celery_tasks.main import celery_app

# 容联云通讯的ID信息
accId = '8aaf070881368efb01816de074bc1090'
accToken = '5b60d90b317b409683b55c2d5704073d'
appId = '8aaf070881368efb01816de075a51097'


@celery_app.task(name='send_sms_code')  # 使用装饰器注册任务
def send_sms_code(mobile, sms_code):
    '''
    发送短信的celery异步任务
    :param mobile: 手机号
    :param sms_code: 验证码
    '''

    # 6、利用容联云通讯发送短信验证码
    sdk = SmsSDK(accId, accToken, appId)
    sdk.sendMessage('1', mobile, (sms_code, constants.SMS_CODE_REDIS_EXPIRES // 60))